<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item  style="font-size: 35px">订单编号{{ getParamFromURL('id') }}签到</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>

    <el-form style="width: 500px;margin-left: 0px">
      <el-form-item label="签到">
        <img :src="ruleForm.avatar" style="float:left;width: 145px;height: 145px;border-radius: 10px">
        <!--上传组件开始-->
        <el-upload
            action="http://localhost:29112/upload/image/signIn"
            name="file"
            :limit=1
            list-type="picture-card"
            :on-success="handleSuccess"
            :on-remove="handleRemove">
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="imageUrl" alt="">
          <div>{{imageUrl}}</div>
        </el-dialog>
        <!--上传组件结束-->
      </el-form-item>

      <el-form-item label="当前位置">
        <el-input style="width: 200px;float:left;" v-model="ruleForm.location"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="save('ruleForm')" style=";float: left; margin-left: 30px">签到</el-button>
        <!--         <a href="" style=";float: left; margin-left: 30px">获取到当前位置</a>-->
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
export default {
  name: "personal"
}
</script>

<script>
import TokenAxios from "@/http/TokenAxios";
import BaseUrl from "@/http/BaseUrl";

export default {
  methods: {
    getParamFromURL(param) {
      const urlParams = new URLSearchParams(window.location.search);
      return urlParams.get(param);
    },
    handleRemove(file, fileList) {
      this.imageUrl = "";
      console.log(file, fileList);
      let url = BaseUrl.SINGIN+'/upload/image/user-avatar/remove?url=' + file.response.data;
      TokenAxios.post(url).then((response) => {
        if (response.data.state === 20000) {
          this.$message.success("服务器文件删除成功");
        }
      })
    },
    handlePictureCardPreview(file) {
      debugger
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;

    },
    handleSuccess(response, file, fileList) {
      debugger
      console.log(response.data)
      this.imageUrl = response.data.url;
      this.ruleForm.avatar=this.imageUrl
      console.log(this.imageUrl)
      // debugger
    },
    save(formName) {
      // this.$refs[formName].validata((valid) => {
      //   if (valid) {
      console.log(this.getParamFromURL('id'))
          // let url = BaseUrl.ADMIN_ACCOUNT + '/sign-ins/add-new/serialNumber='+this.getParamFromURL('id');
          let url = BaseUrl.ADMIN_ACCOUNT + '/sign-ins/add-new/'+this.getParamFromURL('id');
          console.log('url = ' + url);
          let formData = this.qs.stringify(this.ruleForm);
          console.log('formData = ' + formData);
          this.ruleForm.imageUrl=this.imageUrl;
          TokenAxios.post(url, this.ruleForm).then((response) => {
            let jsonResult = response.data;
            console.log(jsonResult);
            if (jsonResult.state == 20000) {
              this.$message({
                showClose: true,
                message: '签到成功！',
                type: 'success'
              });
              // console.log(this.ruleForm.imageUrl)
              // this.ruleForm.avatar=this.ruleForm.imageUrl;
              // console.log(this.ruleForm.avatar)
            }else{
              this.$message.error(jsonResult.message);
            }
          })
      //   }
      // // })
    }
  },

  data() {
    return {
      ruleForm :{location:'',imageUrl:''} ,
      loginInfo: localStorage.loginInfo ? JSON.parse(localStorage.loginInfo) : null,
      imageUrl: '',
      dialogImageUrl: '',
      dialogVisible: false,
      rules: {
        location: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 4, max: 15, message: '长度在 4 到 15 个字符', trigger: 'blur'}
        ],
        imageUrl: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 4, max: 15, message: '长度在 4 到 15 个字符', trigger: 'blur'}
        ],
      }
    }
  }
}
</script>
